package com.acwing.partition10;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author `RKC`
 * @date 2021/12/2 10:50
 */
public class AC908最大不相交区间数量 {


    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int[][] intervals = new int[n][2];
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split(" ");
            intervals[i][0] = Integer.parseInt(s[0]);
            intervals[i][1] = Integer.parseInt(s[1]);
        }
        writer.write(greedy(intervals) + "\n");
        writer.flush();
    }

    private static int greedy(int[][] intervals) {
        //按照右端点进行排序，本质上和区间选点是一样的，区间选点能得出不相交的区间集合数量
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
        int answer = 0, end = -0x3f3f3f3f;
        for (int i = 0; i < intervals.length; i++) {
            if (intervals[i][0] > end) {
                answer++;
                end = intervals[i][1];
            }
        }
        return answer;
    }
}
